const storage = require("../utils/storage");
const api = require("../utils/api");
const constant = require('../utils/constant');
const app = getApp();
Component({
  data: {
    selected: null,
    isTabBarShow: true,
    color: "#7A7E83",
    selectedColor: "#0C3A20",
    menuWidth: 0,
    list: [
      {
        pagePath: "/pages/index/index",
        iconPath: "/assets/icons/home.png",
        selectedIconPath: "/assets/icons/home-fill.png",
        text: "首页",
        type: ""
      }, 
      {
        pagePath: "/pages/list/list",
        iconPath: "/assets/icons/all.png",
        selectedIconPath: "/assets/icons/all-fill.png",
        text: "找货",
        type: ""
      },
      {
        pagePath: "/pages/news/news",
        iconPath: "/assets/icons/cart-Empty.png",
        selectedIconPath: "/assets/icons/cart-Empty-fill.png",
        text: "头条",
        type: "button"
      },
      {
        pagePath: "/pages/personal/personal",
        iconPath: "/assets/icons/account.png",
        selectedIconPath: "/assets/icons/account-fill.png",
        text: "我的",
        type: "button"
      }
    ],
    getPhoneNumber: null
  },
  created(){
    this.setData({
      getPhoneNumber: this.selectComponent("#getPhoneNumber")
    })
  },
  // 组件生命周期函数-在组件实例进入页面节点树时执行
  attached() {
    let that = this;
    wx.getSystemInfo({
      success(res) {
        that.setData({
          menuWidth:parseInt(res.windowWidth/5) > 48 ? 48+(parseInt(res.windowWidth/5)-48)/2:parseInt(res.windowWidth/5)
        })
      },
    })
  },
  methods: {
    switchTab(e) {
      const data = e.currentTarget.dataset;
      const url = data.path;
      app.globalData.isSideShow = false;
      wx.switchTab({url});
    },
    jumpToAddToStore(){
      wx.reLaunch({
        url: '/pages/addToStore/addToStore'
      })
    }
  }
})